#! /bin/bash

DATAX_HOME=/opt/module/datax

#DataX导出路径不允许存在空文件，该函数作用为清理空文件
handle_export_path(){
  for i in `hadoop fs -ls -R $1 | awk '{print $8}'`; do
    hadoop fs -test -z $i
    if [[ $? -eq 0 ]]; then
      echo "$i文件大小为0，正在删除"
      hadoop fs -rm -r -f $i
    fi
  done
}

#数据导出
export_data() {
  datax_config=$1
  export_dir=$2
  handle_export_path $export_dir
  $DATAX_HOME/bin/datax.py -p"-Dexportdir=$export_dir" $datax_config
}

case $1 in
"ads_finish_by_course")
export_data /opt/module/datax/job/export/edu_report.ads_finish_by_course.json /warehouse/edu/ads/ads_finish_by_course
;;
"ads_finish_course_sum")
export_data /opt/module/datax/job/export/edu_report.ads_finish_course_sum.json /warehouse/edu/ads/ads_finish_course_sum
;;
"ads_user_change")
export_data /opt/module/datax/job/export/edu_report.ads_user_change.json /warehouse/edu/ads/ads_user_change
;;
"ads_user_retention")
export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
;;
"ads_user_stats")
export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
;;
"ads_page_path")
export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehouse/edu/ads/ads_page_path
;;
"ads_traffic_order_by_channel")
export_data /opt/module/datax/job/export/edu_report.ads_traffic_order_by_channel.json /warehouse/edu/ads/ads_traffic_order_by_channel
;;
"ads_traffic_stats_by_channel")
export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_channel.json /warehouse/edu/ads/ads_traffic_stats_by_channel
;;
"ads_test_paper")
export_data /opt/module/datax/job/export/edu_report.ads_test_paper.json /warehouse/edu/ads/ads_test_paper
;;
"ads_test_course")
export_data /opt/module/datax/job/export/edu_report.ads_test_course.json /warehouse/edu/ads/ads_test_course
;;
"ads_order_integration")
export_data /opt/module/datax/job/export/edu_report.ads_order_integration.json /warehouse/edu/ads/ads_order_integration
;;
"ads_order_by_province")
export_data /opt/module/datax/job/export/edu_report.ads_order_by_province.json /warehouse/edu/ads/ads_order_by_province
;;
"ads_play_by_chapter")
export_data /opt/module/datax/job/export/edu_report.ads_play_by_chapter.json /warehouse/edu/ads/ads_play_by_chapter
;;
"ads_play_by_course")
export_data /opt/module/datax/job/export/edu_report.ads_play_by_course.json /warehouse/edu/ads/ads_play_by_course
;;
"ads_paper_score_page")
export_data /opt/module/datax/job/export/edu_report.ads_paper_score_page.json /warehouse/edu/ads/ads_paper_score_page
;;
"ads_question_accuracy")
export_data /opt/module/datax/job/export/edu_report.ads_question_accuracy.json /warehouse/edu/ads/ads_question_accuracy
;;
"ads_course_order")
export_data /opt/module/datax/job/export/edu_report.ads_course_order.json /warehouse/edu/ads/ads_course_order
;;
"ads_course_review")
export_data /opt/module/datax/job/export/edu_report.ads_course_review.json /warehouse/edu/ads/ads_course_review
;;
"ads_order_by_category")
export_data /opt/module/datax/job/export/edu_report.ads_order_by_category.json /warehouse/edu/ads/ads_order_by_category
;;
"ads_order_by_subject")
export_data /opt/module/datax/job/export/edu_report.ads_order_by_subject.json /warehouse/edu/ads/ads_order_by_subject
;;
"ads_new_buyer_stats")
export_data /opt/module/datax/job/export/edu_report.ads_new_buyer_stats.json /warehouse/edu/ads/ads_new_buyer_stats
;;
"ads_age_order")
export_data /opt/module/datax/job/export/edu_report.ads_age_order.json /warehouse/edu/ads/ads_age_order
;;
"ads_user_action")
export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action
;;
"ads_category_videoplay_retention")
export_data /opt/module/datax/job/export/edu_report.ads_category_videoplay_retention.json /warehouse/edu/ads/ads_category_videoplay_retention
;;
"ads_subject_idvideoplay_retention")
export_data /opt/module/datax/job/export/edu_report.ads_subject_idvideoplay_retention.json /warehouse/edu/ads/ads_subject_idvideoplay_retention
;;
"ads_course_idvideoplay_retention")
export_data /opt/module/datax/job/export/edu_report.ads_course_idvideoplay_retention.json /warehouse/edu/ads/ads_course_idvideoplay_retention
;;
  "all")
export_data /opt/module/datax/job/export/edu_report.ads_finish_by_course.json /warehouse/edu/ads/ads_finish_by_course
export_data /opt/module/datax/job/export/edu_report.ads_finish_course_sum.json /warehouse/edu/ads/ads_finish_course_sum
export_data /opt/module/datax/job/export/edu_report.ads_user_change.json /warehouse/edu/ads/ads_user_change
export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehouse/edu/ads/ads_page_path
export_data /opt/module/datax/job/export/edu_report.ads_traffic_order_by_channel.json /warehouse/edu/ads/ads_traffic_order_by_channel
export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_channel.json /warehouse/edu/ads/ads_traffic_stats_by_channel
export_data /opt/module/datax/job/export/edu_report.ads_test_paper.json /warehouse/edu/ads/ads_test_paper
export_data /opt/module/datax/job/export/edu_report.ads_test_course.json /warehouse/edu/ads/ads_test_course
export_data /opt/module/datax/job/export/edu_report.ads_order_integration.json /warehouse/edu/ads/ads_order_integration
export_data /opt/module/datax/job/export/edu_report.ads_order_by_province.json /warehouse/edu/ads/ads_order_by_province
export_data /opt/module/datax/job/export/edu_report.ads_play_by_chapter.json /warehouse/edu/ads/ads_play_by_chapter
export_data /opt/module/datax/job/export/edu_report.ads_play_by_course.json /warehouse/edu/ads/ads_play_by_course
export_data /opt/module/datax/job/export/edu_report.ads_paper_score_page.json /warehouse/edu/ads/ads_paper_score_page
export_data /opt/module/datax/job/export/edu_report.ads_question_accuracy.json /warehouse/edu/ads/ads_question_accuracy
export_data /opt/module/datax/job/export/edu_report.ads_course_order.json /warehouse/edu/ads/ads_course_order
export_data /opt/module/datax/job/export/edu_report.ads_course_review.json /warehouse/edu/ads/ads_course_review
export_data /opt/module/datax/job/export/edu_report.ads_order_by_category.json /warehouse/edu/ads/ads_order_by_category
export_data /opt/module/datax/job/export/edu_report.ads_order_by_subject.json /warehouse/edu/ads/ads_order_by_subject
export_data /opt/module/datax/job/export/edu_report.ads_new_buyer_stats.json /warehouse/edu/ads/ads_new_buyer_stats
export_data /opt/module/datax/job/export/edu_report.ads_age_order.json /warehouse/edu/ads/ads_age_order
export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action
export_data /opt/module/datax/job/export/edu_report.ads_category_videoplay_retention.json /warehouse/edu/ads/ads_category_videoplay_retention
export_data /opt/module/datax/job/export/edu_report.ads_subject_idvideoplay_retention.json /warehouse/edu/ads/ads_subject_idvideoplay_retention
export_data /opt/module/datax/job/export/edu_report.ads_course_idvideoplay_retention.json /warehouse/edu/ads/ads_course_idvideoplay_retention
;;
esac